package com.example.helloworld;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper {

	private Context context;
	public DBHelper(Context context, String name, CursorFactory factory,
			int version) {
		super(context, "my.db", factory, version);
		// TODO Auto-generated constructor stub
		this.context = context;
	}

	public String getNames(){
		Cursor cs = getWritableDatabase().rawQuery("select * from test", null);
		StringBuilder sb = new StringBuilder();
		for(cs.moveToFirst();!cs.isAfterLast();cs.moveToNext()){
			sb.append(cs.getString(0));
		}		
		cs.close();
		return sb.toString();
	}
	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		db.execSQL("create table if not exists test (name TEXT primary key)");
		db.execSQL("insert into test values('successful')");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		db.execSQL("drop table test");
	}

}
